package com.wanfajie.smsdistribute.template.convert

interface TemplateConvertable {
    fun <R> convert(converter: TemplateConverter<R>): R

    fun <R> convert(before: (CharSequence) -> Unit = {}, each: (CharSequence, Pair<Int, Int>) -> Unit, after: () -> R): R {

        return convert(object : TemplateConverter<R> {
            override fun setRawMaterial(s: CharSequence) = before.invoke(s)

            override fun mark(name: CharSequence, e: Pair<Int, Int>) = each.invoke(name, e)

            override fun convert(): R = after.invoke()
        })
    }
}
